package sopa.java.regexp;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

// http://java.sun.com/javase/7/docs/api/java/util/regex/Pattern.html

public class RegExp
{
    /**
     * @param regex
     * @param inputArray
     */
    public static void matches(String regex, String ... inputArray)
    {
        Pattern p = Pattern.compile(regex);
        for (String input : inputArray)
        {
            Matcher m = p.matcher(input);
            if (m.matches()){
                System.out.println("Match:    " + regex + " --> " + input);
            }
            else
            {
                System.out.println("No match: " + regex + " --> " + input);
            }
        }
    }
    

    /**
     * @param args
     */
    public static void main(String[] args)
    {
        matches("[abc]z", "az", "bz");
        matches("[^abc]z", "qz");
        matches("[a-zA-Z]", "Q");
        matches("[0-9&&[^345]]", "1");  // intersection
        matches("a.\\d\\s\\S\\w\\W", "aq1 bc:");
        matches("a*b?c+d{2}e{2,}f{1,3}", "cddeeef", "aaabcddeeeff");
    }

}
